package gameElements;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;

/**
 * GfxElement.java
 * 
 * This is the (abstract) super class of all the grafic elements used in the game.
 * 
 * Fredrik Wallenius and Peter Steiner 
 * DP08 - KTH - 2009*
 */
public abstract class GfxElement {
	
	protected double x, y;				 	// Position
	protected double dx, dy; 				// Velocity
	protected Color color;
	protected Rectangle boundBox;
	protected Boolean destroyable;
	protected Boolean causeBounce;
	protected Boolean killMe;		//Set to true when it's to be removed
	
	/**
	 * 
	 * @param x_	Initial x position of the element
	 * @param y_	Initial y position of the element
	 * @param color_	Color of the object
	 */
	public GfxElement(double x_, double y_,  Color color_) {
		this.x = x_; this.y = y_;
		this.color = color_;
		destroyable = false;
		causeBounce = true;
		boundBox = null;
		killMe = false;
	}
	
	/**
	 * Set the bounding box borders 
	 * @param x_
	 * @param y_
	 */
	public void setBoundingBox(int x_, int y_){
		boundBox = new Rectangle();
		boundBox.width = x_;
		boundBox.height = y_;
	}
	
	
	
	/**
	 * 
	 * @param x_
	 * @param y_
	 * @param color_
	 * @param causeBounce_
	 * @param destroyable_
	 */
	public GfxElement(double x_, double y_,  Color color_, Boolean causeBounce_, Boolean destroyable_) {
		this.x = x_; this.y = y_;
		this.color = color_;
		this.boundBox = null;
		destroyable = destroyable_;
		causeBounce = causeBounce_;
		killMe = false;
	}
	
	/**
	 * Set this elements speed in x and y axis direction
	 * @param dx
	 * @param dy
	 */
	public void setVelocity(double dx, double dy) {
		this.dx = dx; this.dy = dy;
	}
	
	/**
	 * @return Boolean, is this brick destroyable
	 */
	public Boolean isDestroyable() { return destroyable; } 
	
	/**
	 * @return Boolean, does this element cause bounce
	 */
	public Boolean isCausingBounce() { return causeBounce; } 
	
	/**
	 * @return True/false if this brick is ready to be terminated
	 */
	public Boolean getKillMe() { 
			return killMe; 
	} 
	
	public void cDetect(ArrayList<GfxElement> allElements){}
	
	/**
	 * Called for moving the element one iteration according so the set speed.
	 */
	public void move() {
		x += dx; y += dy;
		this.constrain();
		return;
	}
	

	
	protected void constrain(){}
	
	
	public Color getColor(){ return color;}
	/**
	 * @return x upper left corner
	 */
	public double getX(){ return x;}
	/**
	 * @return y upper left corner
	 */
	public double getY(){ return y;}
	/**
	 * @return speed Dx x axis
	 */
	public double getDx(){ return dx;}
	/**
	 * @return speed Dy y axis
	 */
	public double getDy(){ return dy;}
	
	
}
